package com.develop.wechatpay.controller;

import com.alibaba.fastjson.JSONObject;
import com.develop.wechatpay.domain.WechatPayModel;
import com.develop.wechatpay.service.WeChatPayOrderService;
import com.develop.wechatpay.util.HttpUtils;
import com.develop.wechatpay.util.JSONObjectUtil;
import com.wechat.pay.contrib.apache.httpclient.constant.WechatPayHttpHeaders;
import com.wechat.pay.contrib.apache.httpclient.notification.Notification;
import com.wechat.pay.contrib.apache.httpclient.notification.NotificationHandler;
import com.wechat.pay.contrib.apache.httpclient.notification.NotificationRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.ParserConfigurationException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/notifica")
@Slf4j
public class WeChatPayNotificaController {

    @Autowired
    private WeChatPayOrderService weChatPayOrderService;

    //    @PostMapping("/notify")
    public JSONObject getNativeNotify(HttpServletRequest request, HttpServletResponse response) {
        return weChatPayOrderService.getNativeNotify(request, response);
    }

    @PostMapping("/wsnotify")
    public synchronized String getWSNativeNotify(HttpServletRequest request, HttpServletResponse response) throws ParserConfigurationException {
        String wsNativeNotify = weChatPayOrderService.getWSNativeNotify(request, response);
        log.info("返回旺盛xml:" + wsNativeNotify);
        return wsNativeNotify;
    }


}
